package controllers

import (
	"time"
)

type (
	Error struct {
		StatusCode int    `json:"StatusCode"`
		ErrCode    int    `json:"errCode"`
		ErrInfo    string `json:"errInfo"`
	}
	//Response struct {
	//	Data    interface{} `json:"data"`
	//	ErrCode int         `json:"errCode"`
	//	ErrInfo string      `json:"errInfo"`
	//}
	UserSecert struct {
		UID       int64     `json:"uid"`
		ExpiredAt time.Time `json:"expiredAt"`
		Platform  string    `json:"platform"`
	}
)

var (
	errCodes = map[int]string{
		40001: "用户认证失败",
		40002: "用户不存在",
		40003: "密码错误",
		20001: "参数错误",
	}
)

func GenError(err error) (e Error) {
	e = Error{
		StatusCode: 200,
		ErrCode:    -1,
		ErrInfo:    err.Error(),
	}
	return
}

func GenErrorMsg(msg string) (e Error) {
	e = Error{
		StatusCode: 200,
		ErrCode:    -1,
		ErrInfo:    msg,
	}
	return
}

func GenErrorCode(code int, err error) (e Error) {
	e = Error{
		StatusCode: 200,
		ErrCode:    code,
		ErrInfo:    err.Error(),
	}
	return
}
